

const ro = new ResizeObserver((entries, observer) => {
    for (const entry of entries) {
        console.log(entry.target.getBoundingClientRect());
        
      // 发生尺寸变化的回调,执行observer 函数的第二个参数 callback
    //   const listeners = elementListeners.get(entry.target as HTMLDivElement);
    //   if (listeners) {
    //     listeners.forEach((listener) => listener(entry.target as HTMLDivElement));
    //   }
    }
  });


export function observer(element: HTMLDivElement, callback: (target:HTMLDivElement)=>void) {
    if (!element) {
      return false;
    }
    // 开始监听
    ro.observe(element);
  }
  
  export function unobserved(
    element: HTMLDivElement | null,
    callback: (target:HTMLDivElement)=>void
  ) {
    if (!element) {
      return false;
    }
  }